package com.angel.architecture.services.impl;

import java.util.ArrayList;
import java.util.Collection;

import org.springframework.beans.factory.annotation.Autowired;

import com.angel.architecture.persistence.beans.ConfigurationParameter;
import com.angel.architecture.services.ConfigurationParameterService;
import com.angel.architecture.services.InitializerConfigurationService;

/**
 *
 * @author William
 */
public class InitializerConfigurationServiceImpl extends GenericServiceImpl implements InitializerConfigurationService {

	private static boolean initialized = false;
	private static Collection<ConfigurationParameter> _parameters = new ArrayList<ConfigurationParameter>();

	@Autowired
	private ConfigurationParameterService configurationParameterService;
	
	public Collection<ConfigurationParameter> initializeConfiguration() {
		Collection<ConfigurationParameter> parameters = new ArrayList<ConfigurationParameter>();
		if(!initialized){
			_parameters.clear();
			
			Collection<Object> collection = this.getConfigurationParameterService().findAll();
			for(Object o: collection){
				parameters.add((ConfigurationParameter) o);
			}
			_parameters.addAll(parameters);
			initialized = true;
		}
		return parameters;
	}

	public Collection<ConfigurationParameter> reinitializeConfiguration() {
		initialized = false;
		return this.initializeConfiguration();
	}

	public boolean isInitialized() {
		return initialized;
	}

	/**
	 * @return the configurationParameterService
	 */
	public ConfigurationParameterService getConfigurationParameterService() {
		return configurationParameterService;
	}

	/**
	 * @param configurationParameterService the configurationParameterService to set
	 */
	public void setConfigurationParameterService(
			ConfigurationParameterService configurationParameterService) {
		this.configurationParameterService = configurationParameterService;
	}
}